package com.masterrabbit.gmh.controller;

import com.masterrabbit.gmh.domain.Merchants;
import com.masterrabbit.gmh.service.MerchantsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

@RestController
@RequestMapping("/merchants")
public class MerchantsController {
    @Autowired
    private MerchantsService merchantsService;

    @GetMapping("/getMerchantsByMerchantId")
    public List<Merchants> getMerchantsByMerchantId(Integer merchantId) {
        List<Merchants> merchants = new ArrayList<>();
        List<Merchants> merchant = merchantsService.getMerchantsByMerchantId(merchantId);
        for (Merchants merchant1 : merchant) {
            List<String> strings = merchantsService.selectByProductId(merchant1.getBusinessLicenseImageId());
            merchant1.setStorefrontImageUrl(strings);
            merchants.add(merchant1);
        }
        return merchants;
    }

    @GetMapping("/selectImg")
    public List<String> selectImg(Integer productId) {
        return merchantsService.selectByProductId(productId);
    }

}
